From 8306baac6f817aea60eb6e7acfac96cbb007ed5a Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Wed, 17 Mar 2004 17:13:18 +0000 Subject: [PATCH] bitkeeper revision 1.807 (4058872eScocwS_6SkwoZWFMzDk9Nw) utils.c, control_if.h: Move shared controller-interface definitions out of the xenolinux tree. console_client.py: Fix console client. control_if.h: bk cp xenolinux-2.4.25-sparse/include/asm-xeno/control_if.h tools/xend/lib/control_if.h Rewritten the Xen control daemon in Python, with C extensions for the low-level bits. All our Python libraries now throw exceptions on error rather than returning error codes --- this will require our higher-level scripts to be updated at some point. new file --- .rootkeys | 1 + tools/xenctl/lib/console_client.py | 48 +++++++++++++++++++----------- tools/xend/lib/control_if.h | 35 ++++++++++++++++++++++ tools/xend/lib/utils.c | 2 +- tools/xend/setup.py | 3 +- 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 tools/xend/lib/control_if.h diff --git a/.rootkeys b/.rootkeys index 5aed5695a8..b000ea2a90 100644 --- a/.rootkeys +++ b/.rootkeys @@ -96,6 +96,7 @@ 40431ac64Hj4ixUnKmlugZKhXPFE_Q tools/xend/Makefile 4055ad95Se-FqttgxollqOAAHB94zA tools/xend/lib/__init__.py 4055ad97wMLUj0BZT0e_T0EwQN0Bvw tools/xend/lib/console.py +4048c0ddsF0WrU7HUzTvg1MJoCIfWg tools/xend/lib/control_if.h 4054a301VEag2GwrBrFBna5U1BGlLA tools/xend/lib/main.py 4055ad9ah9IuC3sJT2c_gYIFY5Tw_g tools/xend/lib/manager.py 40431ac8wrUEj-XM7B8smFtx_HA7lQ tools/xend/lib/utils.c diff --git a/tools/xenctl/lib/console_client.py b/tools/xenctl/lib/console_client.py index d4dfb78e66..df15d6f1d3 100644 --- a/tools/xenctl/lib/console_client.py +++ b/tools/xenctl/lib/console_client.py @@ -5,7 +5,17 @@ # Copyright (c) 2004, K A Fraser ############################################## -import errno, os, signal, socket, struct, sys, termios +import errno, os, signal, socket, struct, sys + +from termios import * +# Indexes into termios.tcgetattr() list. +IFLAG = 0 +OFLAG = 1 +CFLAG = 2 +LFLAG = 3 +ISPEED = 4 +OSPEED = 5 +CC = 6 def __child_death(signum, frame): global stop @@ -14,7 +24,6 @@ def __child_death(signum, frame): def __recv_from_sock(sock): global stop stop = False - print "************ REMOTE CONSOLE: CTRL-] TO QUIT ********" while not stop: try: data = sock.recv(1) @@ -22,8 +31,6 @@ def __recv_from_sock(sock): except socket.error, error: if error[0] != errno.EINTR: raise - print - print "************ REMOTE CONSOLE EXITED *****************" os.wait() def __send_to_sock(sock): @@ -41,21 +48,28 @@ def connect(host,port): struct.pack('ii', 0, 0)) sock.connect((host,port)) - oattrs = termios.tcgetattr(0) - nattrs = termios.tcgetattr(0) - nattrs[3] = nattrs[3] & ~(termios.ECHO | termios.ICANON) - nattrs[6][termios.VMIN] = 1 - nattrs[6][termios.VTIME] = 0 - termios.tcsetattr(0, termios.TCSAFLUSH, nattrs) + oattrs = tcgetattr(0) + nattrs = tcgetattr(0) + nattrs[IFLAG] = nattrs[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON) + nattrs[OFLAG] = nattrs[OFLAG] & ~(OPOST) + nattrs[CFLAG] = nattrs[CFLAG] & ~(CSIZE | PARENB) + nattrs[CFLAG] = nattrs[CFLAG] | CS8 + nattrs[LFLAG] = nattrs[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG) + nattrs[CC][VMIN] = 1 + nattrs[CC][VTIME] = 0 - try: - if os.fork(): - signal.signal(signal.SIGCHLD, __child_death) + if os.fork(): + signal.signal(signal.SIGCHLD, __child_death) + print "************ REMOTE CONSOLE: CTRL-] TO QUIT ********" + tcsetattr(0, TCSAFLUSH, nattrs) + try: __recv_from_sock(sock) - else: - __send_to_sock(sock) - finally: - termios.tcsetattr(0, termios.TCSAFLUSH, oattrs) + finally: + tcsetattr(0, TCSAFLUSH, oattrs) + print + print "************ REMOTE CONSOLE EXITED *****************" + else: + __send_to_sock(sock) if __name__ == '__main__': connect(str(sys.argv[1]),int(sys.argv[2])) diff --git a/tools/xend/lib/control_if.h b/tools/xend/lib/control_if.h new file mode 100644 index 0000000000..299feebb8d --- /dev/null +++ b/tools/xend/lib/control_if.h @@ -0,0 +1,35 @@ +/****************************************************************************** + * control_if.h + * + * Interface to server controller (e.g., 'xend'). This header file defines the + * interface that is shared with guest OSes. + * + * Copyright (c) 2004, K A Fraser + */ + +#ifndef __CONTROL_IF_H__ +#define __CONTROL_IF_H__ + +typedef struct { + u8 type; /* echoed in response */ + u8 subtype; /* echoed in response */ + u8 id; /* echoed in response */ + u8 length; /* number of bytes in 'msg' */ + unsigned char msg[60]; /* type-specific message data */ +} control_msg_t; + +#define CONTROL_RING_SIZE 8 +typedef unsigned int CONTROL_RING_IDX; +#define MASK_CONTROL_IDX(_i) ((_i)&(CONTROL_RING_SIZE-1)) + +typedef struct { + control_msg_t tx_ring[CONTROL_RING_SIZE]; /* guest-OS -> controller */ + control_msg_t rx_ring[CONTROL_RING_SIZE]; /* controller -> guest-OS */ + CONTROL_RING_IDX tx_req_prod, tx_resp_prod; + CONTROL_RING_IDX rx_req_prod, rx_resp_prod; +} control_if_t; + +#define CMSG_CONSOLE 0 +#define CMSG_CONSOLE_DATA 0 + +#endif /* __CONTROL_IF_H__ */ diff --git a/tools/xend/lib/utils.c b/tools/xend/lib/utils.c index c5954043d6..24064b6a45 100644 --- a/tools/xend/lib/utils.c +++ b/tools/xend/lib/utils.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include "control_if.h" /* Needed for Python versions earlier than 2.3. */ #ifndef PyMODINIT_FUNC diff --git a/tools/xend/setup.py b/tools/xend/setup.py index 3dc84d61fa..6a2c9225d7 100644 --- a/tools/xend/setup.py +++ b/tools/xend/setup.py @@ -2,8 +2,7 @@ from distutils.core import setup, Extension utils = Extension("utils", - include_dirs = ["../xc/lib", - "../../xenolinux-sparse/include"], + include_dirs = ["../xc/lib"], library_dirs = ["../xc/lib"], libraries = ["xc"], sources = ["lib/utils.c"]) -- 2.30.2